package ${packageName}.configure;

<#if isNeedCommon >
import ${packageName}.common.entity.constant.EndpointConstant;
import ${packageName}.common.handler.JupiterAccessDeniedHandler;
import ${packageName}.common.handler.JupiterAuthExceptionEntryPoint;
import org.springframework.beans.factory.annotation.Autowired;
</#if>
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;

/**
 * 资源服务器配置
 *
 */
@Configuration
@EnableResourceServer
public class ResourceServerConfigure extends ResourceServerConfigurerAdapter {

<#if isNeedCommon == false>//</#if>    @Autowired
<#if isNeedCommon == false>//</#if>    private JupiterAccessDeniedHandler accessDeniedHandler;
<#if isNeedCommon == false>//</#if>    @Autowired
<#if isNeedCommon == false>//</#if>    private JupiterAuthExceptionEntryPoint exceptionEntryPoint;

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.headers().frameOptions().disable()
                .and().csrf().disable()
<#if isNeedCommon == false>//</#if>                .requestMatchers().antMatchers(EndpointConstant.ALL)
<#if isNeedCommon == false>//</#if>                .and()
                .authorizeRequests()
                // .antMatchers("no_auth").permitAll()
<#if isNeedCommon == false>//</#if>                .antMatchers(EndpointConstant.ALL).authenticated()
                .and().httpBasic();
    }

    @Override
    public void configure(ResourceServerSecurityConfigurer resources) {
<#if isNeedCommon == false>//</#if>        resources.authenticationEntryPoint(exceptionEntryPoint).accessDeniedHandler(accessDeniedHandler);
    }
}
